//
//  LoginViewController.m
//  大轮胎
//
//  Created by Apple on 17/3/25.
//  Copyright © 2017年 zyc. All rights reserved.
//

#import "LoginViewController.h"
#import <SDAutoLayout.h>
@interface LoginViewController ()<UITextFieldDelegate>
//<UITableViewDelegate,UITableViewDataSource>
{
    // 背景图
    UIImageView *imgView;
    // 返回按钮
    UIButton *returnButton;
    // 头视图
    UIView *headView;
    //头像按钮
    UIButton *imageHeader;
    // 手机图片
    UIImageView *phoneImage;
    // 密码图片
    UIImageView *passwordImage;
    // 手机框
    UITextField *phoneTF;
    //密码框
    UITextField *passwordTF;
    // 登录按钮
    UIButton *loginButton;
    // zhuce
    UIButton *RegisteredButton;
    // 忘记密码
    UIButton *ForgotPasswordButton;
}
@property (nonatomic,strong) UITableView *theTable;
@end

@implementation LoginViewController

// 表格
-(UITableView *)theTable{
    if (!_theTable) {
        _theTable=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) ];
    }
    _theTable.backgroundColor=[UIColor clearColor];
    _theTable.backgroundView=imgView;
    _theTable.separatorStyle=UITableViewCellSeparatorStyleNone;
//    _theTable.delegate=self;
//    _theTable.dataSource=self;
    return _theTable;
}
- (void)viewDidLoad {
    [super viewDidLoad];
   
    
    [self fangfa];
    
}

-(void)fangfa{
    // imgView  占全屏
    imgView=[[UIImageView alloc]initWithFrame:CGRectMake(0, 40, self.view.frame.size.width, self.view.frame.size.height)];
    imgView.image=[UIImage imageNamed:@"20141103130549_kWZrF"];
//    [self.view addSubview:imgView];bg1.JPG
    // 表格添加到imgView上
    [self.view addSubview:self.theTable];
    // headView   view   预计添加到表格头视图
    headView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 390)];
    headView.backgroundColor=[UIColor clearColor];
    // headView 添加到 theTable 表格头视图
    self.theTable.tableHeaderView=headView;
    
    // 返回按钮
    returnButton=[[UIButton alloc]initWithFrame:CGRectMake(self.view.frame.size.width-50, 30, 30, 30)];
    [returnButton setImage:[UIImage imageNamed:@"X-2.png"] forState:UIControlStateNormal];
    [returnButton addTarget:self action:@selector(returnB) forControlEvents:UIControlEventTouchUpInside];
    // 返回按钮添加到 headView 上
    [headView addSubview:returnButton];
    
    //  头像按钮
    imageHeader=[[UIButton alloc]initWithFrame:CGRectMake(self.view.frame.size.width/2-50, 70, 100, 100)];
    imageHeader.layer.cornerRadius=50;
    imageHeader.layer.masksToBounds=YES;
    [imageHeader setImage:[UIImage imageNamed:@"设施小猫.png"] forState:0];
    imageHeader.backgroundColor=[UIColor groupTableViewBackgroundColor];
    [headView addSubview:imageHeader];
    // 手机图片
    phoneImage=[[UIImageView alloc]initWithFrame:CGRectMake(30, 190, 30, 30)];
    phoneImage.image=[UIImage imageNamed:@"手机.png"];
    // 账号框
    phoneTF=[[UITextField alloc]initWithFrame:CGRectMake(70, 190, self.view.frame.size.width-95, 30)];
    phoneTF.textColor=[UIColor whiteColor];
    phoneTF.placeholder=@"手机号";
//    phoneTF.clearsOnBeginEditing = YES;
    phoneTF.keyboardType=UIKeyboardTypeNumberPad;
    phoneTF.adjustsFontSizeToFitWidth=YES;
    phoneTF.borderStyle=UITextBorderStyleNone;
    phoneTF.clearButtonMode=UITextFieldViewModeWhileEditing;
    
  

    
    
    UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(70,219, self.view.frame.size.width-95, 0.4)];
    lineView.backgroundColor = [UIColor whiteColor];
    [headView addSubview:lineView];
    
    // 密码图片
    passwordImage=[[UIImageView alloc]initWithFrame:CGRectMake(30, 240, 30, 30)];
    passwordImage.image=[UIImage imageNamed:@"密码.png"];
    // 密码框
    passwordTF=[[UITextField alloc]initWithFrame:CGRectMake(70, 240, self.view.frame.size.width-95, 30)];
    passwordTF.textColor=[UIColor whiteColor];
    passwordTF.placeholder=@"密码";
    passwordTF.clearButtonMode=YES;
    passwordTF.keyboardType=UIKeyboardTypeDefault;
    passwordTF.secureTextEntry=YES;
    passwordTF.adjustsFontSizeToFitWidth=YES;
    passwordTF.clearButtonMode=UITextFieldViewModeWhileEditing;
    UIView *lineView2 = [[UIView alloc]initWithFrame:CGRectMake(70,269, self.view.frame.size.width-95, 0.4)];
    lineView2.backgroundColor = [UIColor whiteColor];
    [headView addSubview:lineView2];
    
    // 登录按钮
    loginButton=[[UIButton alloc]initWithFrame:CGRectMake(30, 300, self.view.frame.size.width-60, 40)];
    [loginButton setTitle:@"登 录" forState:0];
    [loginButton setTitleColor:[UIColor grayColor] forState:0];
    loginButton.backgroundColor=[UIColor yellowColor];
    loginButton.layer.cornerRadius=8;
    loginButton.layer.masksToBounds=YES;
    [loginButton addTarget:self action:@selector(dengdeng) forControlEvents:UIControlEventTouchUpInside];
    
    // 注册
    RegisteredButton=[[UIButton alloc]initWithFrame:CGRectMake(30, 360, 100, 20)];
    [RegisteredButton setTitle:@"注册使用呦 ！" forState:0];
    [RegisteredButton setTitleColor:[UIColor yellowColor] forState:0];
    RegisteredButton.backgroundColor=[UIColor clearColor];
    [RegisteredButton addTarget:self action:@selector(zhuce) forControlEvents:UIControlEventTouchUpInside];
    RegisteredButton.titleLabel.font=[UIFont systemFontOfSize:14];
    
    // 忘记密码
    ForgotPasswordButton=[[UIButton alloc]initWithFrame:CGRectMake(self.view.frame.size.width-140, 360,100, 30)];
    [ForgotPasswordButton setTitle:@"密码忘掉了" forState:0];
    [ForgotPasswordButton setTitleColor:[UIColor whiteColor] forState:0];
    ForgotPasswordButton.backgroundColor=[UIColor clearColor];
    [ForgotPasswordButton addTarget:self action:@selector(wangji) forControlEvents:UIControlEventTouchUpInside];
    ForgotPasswordButton.titleLabel.font=[UIFont systemFontOfSize:14];
    
//    // layout 手机图片
//    phoneImage.sd_layout.
//    topSpaceToView(imageHeader,20).
//    leftSpaceToView(self.view,30).
//    widthIs(20).heightIs(40);
//    // 账号框
//    phoneTF.sd_layout.
//    topSpaceToView(imageHeader,20).
//    leftSpaceToView(phoneImage,10).
//    rightSpaceToView(self.view,30).
//    heightIs(40);
//    // 密码图片
//    passwordImage.sd_layout.
//    topSpaceToView(phoneTF,20).
//    leftSpaceToView(self.view,30).
//    widthIs(20).heightIs(40);
//    // 密码框
//    passwordTF.sd_layout.
//    topSpaceToView(phoneTF,20).
//    leftSpaceToView(passwordImage,10).
//    rightSpaceToView(self.view,30).
//    heightIs(40);
//    // 登录按钮
//    loginButton.sd_layout.
//    topSpaceToView(passwordTF,20).
//    leftSpaceToView(self.view,30).
//    rightSpaceToView(self.view,30).
//    heightIs(40);
//    // 注册
//    RegisteredButton.sd_layout.
//    leftSpaceToView(self.view,30).
//    topSpaceToView(loginButton,20).
//    widthIs(80).heightIs(20);
//    // 忘记密码
//    ForgotPasswordButton.sd_layout.rightSpaceToView(self.view,30).topSpaceToView(loginButton,20).widthIs(80).heightIs(20);
    
    [headView addSubview:phoneImage];
    [headView addSubview:phoneTF];
    [headView addSubview:passwordImage];
    [headView addSubview:passwordTF];
    [headView addSubview:loginButton];
    [headView addSubview:RegisteredButton];
    [headView addSubview:ForgotPasswordButton];
    
    
    //收起键盘Tap
    
    UITapGestureRecognizer *tableViewGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(commentTableViewTouchInSide)];
    tableViewGesture.numberOfTapsRequired = 1;
    tableViewGesture.cancelsTouchesInView = NO;
    [self.theTable addGestureRecognizer:tableViewGesture];
}

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string;
{  //string就是此时输入的那个字符textField就是此时正在输入的那个输入框返回YES就是可以改变输入框的值NO相反
    
    if ([string isEqualToString:@"\n"])  //按会车可以改变
    {
        return YES;
    }
    
    NSString * toBeString = [phoneTF.text stringByReplacingCharactersInRange:range withString:string]; //得到输入框的内容
    
    if (phoneTF == textField)  //判断是否时我们想要限定的那个输入框
    {
        if ([toBeString length] > 11) { //如果输入框内容大于20则弹出警告
            textField.text = [toBeString substringToIndex:11];
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"请输入正确的手机号码" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
            [alert show];
            return NO;
        }
    }
    return YES;
}
- (void)textFieldDidEndEditing:(UITextField *)textField{
    
    
    
    
    
}
#pragma mark -收起键盘
- (void)commentTableViewTouchInSide{
    [self.view endEditing:YES];
}


-(void)dengdeng{
    
    
    
    
}
-(void)zhuce{
    
}
-(void)wangji{
    
}
//收起键盘
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    
    [self.view endEditing:YES];
    [self.theTable endEditing:YES];
    
}
-(void)returnB{
    [self dismissViewControllerAnimated:NO completion:^{
    }];
}






- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
